package com.itheima.d2_Timer;

import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * ScheduleExecutorService
 */
public class demo2 {
    public static void main(String[] args) {
        //1.创建线程池，做定时器
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(3);
        //
        //2.开启定时任务
        pool.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName()+"输出AAAA");
            }
        },0,2, TimeUnit.SECONDS);

        pool.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getName()+"输出BBB");
            }
        },2,2, TimeUnit.SECONDS);
    }
}
